home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolfedit2 2.0.4 source.sit / WolfEdit2 2.0.4 Source / UBSPDebug.p < prev    next >
Text File  |  1994-11-14  |  3KB  |  144 lines

  1. unit UBSPDebug;
  2.  
  3. interface
  4.     uses
  5.         UBSPTree;
  6.  
  7.     procedure DrawBSPTree (tree: BSPTreePtr; cellSize, borderSize: integer);
  8.     procedure DBSP (tree: BSPTreePtr);
  9.  
  10. implementation
  11.  
  12.     const
  13.  
  14.         bspPatListID = 128;
  15.         vSplitPatIndx = 2;
  16.         hSplitPatIndx = 3;
  17.  
  18.         segThick = 6;
  19.         splitThick = 1;
  20.  
  21.     procedure DrawBSPTree (tree: BSPTreePtr; cellSize, borderSize: integer);
  22.         var
  23.             pitch: integer;
  24.             n: integer;
  25.  
  26.         function Coord (x: integer): integer;
  27.         begin
  28.             Coord := pitch * x div 2;
  29.         end;
  30.  
  31.         procedure DrawSegment (p: SegmentPtr; pat: Pattern);
  32.             var
  33.                 r: Rect;
  34.                 vh, hv: VHSelect;
  35.         begin
  36.             vh := p^.dir;
  37.             hv := VHSelect(1 - ord(vh));
  38.             r.topLeft.vh[vh] := Coord(p^.ends[0]);
  39.             r.botRight.vh[vh] := Coord(p^.ends[1]) + borderSize;
  40.             case p^.face of
  41.                 nw:  begin
  42.                         r.topLeft.vh[hv] := Coord(p^.pos) - segThick;
  43.                         r.botRight.vh[hv] := Coord(p^.pos) + borderSize;
  44.                     end;
  45.                 se:  begin
  46.                         r.topLeft.vh[hv] := Coord(p^.pos);
  47.                         r.botRight.vh[hv] := Coord(p^.pos) + segThick;
  48.                     end;
  49.             end;
  50.             FillRect(r, pat);
  51.             FrameRect(r);
  52.         end;
  53.  
  54.         procedure DrawSegments (p: SegmentPtr);
  55.             var
  56.                 pat: Pattern;
  57.         begin
  58.             GetIndPattern(pat, sysPatListID, n);
  59.             n := n + 1;
  60.             while p <> nil do begin
  61.                     DrawSegment(p, pat);
  62.                     p := p^.next;
  63.                 end;
  64.         end;
  65.  
  66.         procedure DrawSplit (vh: VHSelect; pos: integer; b: Rect);
  67.             var
  68.                 i: integer;
  69.                 pat: Pattern;
  70.                 r: Rect;
  71.                 hv: VHSelect;
  72.         begin
  73.             hv := VHSelect(1 - ord(vh));
  74.             case vh of
  75.                 v: 
  76.                     i := vSplitPatIndx;
  77.                 h: 
  78.                     i := hSplitPatIndx;
  79.             end;
  80.             GetIndPattern(pat, bspPatListID, i);
  81.             r.topLeft.vh[vh] := Coord(b.topLeft.vh[vh]);
  82.             r.topLeft.vh[vh] := Coord(b.botRight.vh[vh]) + borderSize;
  83.             r.topLeft.vh[hv] := Coord(pos) - (splitThick - borderSize) div 2;
  84.             r.botRight.vh[hv] := r.topLeft.vh[hv] + splitThick;
  85.             FillRect(r, pat);
  86.         end;
  87.  
  88.         procedure SplitRect (b: Rect; vh: VHSelect; pos: integer; var b0, b1: Rect);
  89.             var
  90.                 hv: VHSelect;
  91.         begin
  92.             hv := VHSelect(1 - ord(vh));
  93.             b0 := b;
  94.             b1 := b;
  95.             b1.botRight.vh[hv] := pos;
  96.             b0.topLeft.vh[hv] := pos;
  97.         end;
  98.  
  99.         procedure DrawTree (p: BSPTreePtr; b: Rect);
  100.             var
  101.                 p0, p1: BSPTreePtr;
  102.                 b0, b1: Rect;
  103.         begin
  104.             if p <> nil then begin
  105.                     case p^.kind of
  106.                         nonTerminal:  begin
  107.                                 p0 := p^.links[0];
  108.                                 p1 := p^.links[1];
  109.                                 if (p0 <> nil) | (p1 <> nil) then begin
  110.                                         SplitRect(b, p^.splitDir, p^.splitCoord, b0, b1);
  111.                                         DrawTree(p0, b0);
  112.                                         DrawTree(p1, b1);
  113.                                         DrawSplit(p^.splitDir, p^.splitCoord, b);
  114.                                     end;
  115.                             end;
  116.                         terminal: 
  117.                             ;
  118.                     end;
  119.                     DrawSegments(p^.segments);
  120.                 end;
  121.         end;
  122.  
  123.         procedure DrawRoot (p: BSPTreePtr);
  124.             var
  125.                 b: Rect;
  126.         begin
  127.             SetRect(b, 0, 0, 128, 128);
  128.             DrawTree(p, b);
  129.         end;
  130.  
  131.     begin
  132.         pitch := cellSize + borderSize;
  133.         n := 1;
  134.         PenNormal;
  135.         DrawRoot(tree);
  136.     end;
  137.  
  138.     procedure DBSP (tree: BSPTreePtr);
  139.     begin
  140.         ShowDrawing;
  141.         DrawBSPTree(tree, 16, 1);
  142.     end;
  143.  
  144. end.